package com.xs.designpattern;

import lombok.extern.slf4j.Slf4j;

/**
 * @author xs
 */
@Slf4j
public class Main {
    private static final String RED_DRAGON_EMERGES = "红龙现身!";
    private static final String GREEN_DRAGON_SPOTTED = "前方发现绿龙!";
    private static final String BLACK_DRAGON_LANDS = "黑龙降临在你面前!";
    public static void main(String[] args) {
        //GoF 战略模式
        log.info(GREEN_DRAGON_SPOTTED);
        DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
        dragonSlayer.goToBattle();
        log.info(RED_DRAGON_EMERGES);
        dragonSlayer.changeStrategy(new ProjectileStrategy());
        dragonSlayer.goToBattle();
        log.info(BLACK_DRAGON_LANDS);
        dragonSlayer.changeStrategy(new SpellStrategy());
        dragonSlayer.goToBattle();

        // Java 8 function实现策略模式
        log.info(GREEN_DRAGON_SPOTTED);
        dragonSlayer = new DragonSlayer(
            () -> log.info("你用你的神剑砍下了龙的头!"));
        dragonSlayer.goToBattle();
        log.info(RED_DRAGON_EMERGES);
        dragonSlayer.changeStrategy(() -> log.info(
            "你用魔法十字弓射杀龙，它倒在地上死了!"));
        dragonSlayer.goToBattle();
        log.info(BLACK_DRAGON_LANDS);
        dragonSlayer.changeStrategy(() -> log.info(
            "你施展了分解咒语，巨龙就蒸发成了一堆灰尘!"));
        dragonSlayer.goToBattle();

        // Java 8 lambda 实现与枚举策略模式
        log.info(GREEN_DRAGON_SPOTTED);
        dragonSlayer.changeStrategy(LambdaStrategy.Strategy.MELEESTRATEGY);
        dragonSlayer.goToBattle();
        log.info(RED_DRAGON_EMERGES);
        dragonSlayer.changeStrategy(LambdaStrategy.Strategy.PROJECTILESTRATEGY);
        dragonSlayer.goToBattle();
        log.info(BLACK_DRAGON_LANDS);
        dragonSlayer.changeStrategy(LambdaStrategy.Strategy.SPELLSTRATEGY);
        dragonSlayer.goToBattle();
    }
}